// 商品数据
const products = [
    {
        id: 1,
        name: "经典白色T恤",
        price: 99.00,
        description: "100%纯棉，舒适透气，经典百搭款式",
        image: "images/tshirt.jpg",
        details: "这款经典白色T恤采用优质棉料制作，穿着舒适，透气性好。简约的设计风格百搭易搭配，是您衣橱中不可或缺的基础单品。"
    },
    {
        id: 2,
        name: "牛仔裤",
        price: 199.00,
        description: "修身直筒，经典蓝色，耐穿舒适",
        image: "images/jeans.jpg",
        details: "采用优质牛仔面料，穿着舒适有型。经典直筒设计，修身不紧绷，适合日常穿着。"
    },
    {
        id: 3,
        name: "运动鞋",
        price: 299.00,
        description: "轻便透气，减震防滑",
        image: "images/sneakers.jpg",
        details: "专业运动鞋底设计，提供优秀的减震效果。鞋面采用透气网布，让您的双脚保持干爽舒适。"
    }
];

// 渲染商品列表
function renderProducts() {
    const container = document.getElementById('productsContainer');
    
    products.forEach(product => {
        const productCard = document.createElement('div');
        productCard.className = 'product-card';
        productCard.onclick = () => goToDetail(product.id);
        
        productCard.innerHTML = `
            <img src="${product.image}" alt="${product.name}" onerror="this.src='images/placeholder.jpg'">
            <div class="product-info">
                <h2>${product.name}</h2>
                <p class="price">￥${product.price.toFixed(2)}</p>
                <p class="description">${product.description}</p>
            </div>
        `;
        
        container.appendChild(productCard);
    });
}

// 跳转到商品详情页
function goToDetail(productId) {
    window.location.href = `detail.html?id=${productId}`;
}

// 获取URL参数的辅助函数
function getUrlParam(param) {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(param);
}

// 页面加载完成后渲染商品
document.addEventListener('DOMContentLoaded', renderProducts);